package com.cf.mvp.sample.mvp.presenter;

import androidx.lifecycle.Lifecycle;

import com.cf.mvp.mvp.BasePresenter;
import com.cf.mvp.rx.BaseErrorObserver;
import com.cf.mvp.rx.RxLifecycle;
import com.cf.mvp.sample.mvp.contract.NetworkContract;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author yangji
 */
public class NetworkPresenter extends BasePresenter<NetworkContract.Model, NetworkContract.View> implements NetworkContract.Presenter {

    @Override
    public void requestNetwork() {
        Observable.interval(1, TimeUnit.SECONDS)
                .compose(RxLifecycle.bindEvent(getSubject(), Lifecycle.Event.ON_PAUSE))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseErrorObserver<Long>() {
                    @Override
                    public void onNext(Long aLong) {
                        getMvpView().onNetworkSignal(aLong);
                    }
                });
    }

    @Override
    public void responseNetwork(int signal) {

    }
}
